package personal.vivian.aop.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import personal.vivian.aop.annotation.Transform;

@Component
@Aspect
public class TransformPointCut {
    @Autowired
    TransformAOPProcessor transformAOPProcessor;
 @Pointcut("@annotation(personal.vivian.aop.annotation.Transform)")
    public void pointCut(){

    }
    //unbound pointcut parameter-> 去掉Transform transform
    @Around("pointCut()")
   //@Around("@annotation(transform)")
    public Object around(ProceedingJoinPoint pjp) throws Throwable{
        try{
            Transform transform  = ((MethodSignature)pjp.getSignature()).getMethod().getAnnotation(Transform.class);
            return transformAOPProcessor.aopAround(pjp,transform);
        }catch (Throwable e){
            throw e;
        }
    }
}
